﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace SteroMood.StereoMood_Data
{
    [XmlRoot("song")]
    public class Song
    {
        [XmlElement("id")]
        public int Id { get; set; }

        [XmlElement("title")]
        public string Title { get; set; }

        [XmlElement("artist")]
        public string Artist { get; set; }

        /// <summary>
        /// song album
        /// </summary>
        [XmlElement("album")]
        public string Album { get; set; }

        /// <summary>
        /// song page url
        /// </summary>
        [XmlElement("url")]
        public string Url { get; set; }

        /// <summary>
        /// song image
        /// </summary>
        [XmlElement("image_url")]
        public string ImageUrl { get; set; }

        /// <summary>
        /// url of the audio file
        /// </summary>
        [XmlElement("audio_url")]
        public string AudioUrl { get; set; }

        /// <summary>
        /// url of the blog post
        /// </summary>
        [XmlElement("post_url")]
        public string PostUrl { get; set; }


        public override string ToString()
        {
            string rVal = string.Empty;
            if(!string.IsNullOrWhiteSpace(Album))
                rVal += Album.ToUpperFirstCase();

            if (!string.IsNullOrWhiteSpace(Artist))
            {
                if (!string.IsNullOrWhiteSpace(rVal))
                    rVal += ", ";
                rVal += Artist.ToUpperFirstCase();
            }

            if(!string.IsNullOrWhiteSpace(Title))
            {
                if (!string.IsNullOrWhiteSpace(rVal))
                    rVal += " - ";
                rVal += Title.ToUpperFirstCase();
            }
                

            return rVal;
        }
    }

    [XmlRoot("songs")]
    public class Songs
    {
        [XmlElement("song")]
        public List<Song> SongsContainer = new List<Song>();

        public Songs()
        {
            SongsContainer = new List<Song>();
        }
    }

    [XmlRoot("search")]
    public class Search
    {
        /// <summary>
        /// returns a list of a song matching the specified query.
        /// parameters:
        /// q. the text to search for.
        /// type. mood, activity or site.
        /// limit. an integer used to limit the number of results returned per page. the default is 20 (Max 100).
        /// page.the page number to fetch.
        /// </summary>
        public static string Url = "http://www.stereomood.com/api/search.xml";

        [XmlElement("total")]
        public int TotalTrackNumber { get; set; }
        [XmlElement("page")]
        public int PageIndex { get; set; }
        [XmlElement("limit")]
        public int ResultsCountPerPage { get; set; }
        [XmlElement("total_pages")]
        public int TotalPages { get; set; }

        [XmlElement("songs")]
        public Songs SongsContainer { get; set; }

        public Search()
        {
            SongsContainer = new Songs();
        }
    }
}
